package ch.ethz.fcl.metrobuzz.render.techniques.tesselation;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.GLU;

import ch.ethz.fcl.metrobuzz.MBContainer;
import ch.ethz.fcl.metrobuzz.controller.MBController;
import ch.ethz.fcl.metrobuzz.tools.MBGL;
import ch.ethz.fcl.metrobuzz.viewer.MBViewer;

public class TessellationTest {
	private MBViewer view;
	private MBController control;

	public TessellationTest() {
		init();
	}

	public void run() {
		while (true) {
			Display.update();
			control.update();

			Display.sync(60);

			GL11.glPushMatrix();
			view.update();
			MBGL.enableBlend();
			if (MBViewer.newUpdate)
				render();
			GL11.glPopMatrix();
		}
	}

	private void init() {
		MBContainer container = new MBContainer();

		int width = 800;
		int height = 600;

		view = new MBViewer(MBViewer.ProjectionType.Perspective, container);
		view.createDisplay(width, height, width, height, "Circos Test");
		view.getCamera().disablePan();
		view.getCamera().initDistance(2.5f);

		control = new MBController(container);
	}

	private void render() {
		// first polygon: a star-5 vertices and color information
		double star[][] = { { 0.6f, -0.1f }, { 1.35f, 1.4f }, { 2.1f, -0.1f },
				{ 0.6f, 0.9f }, { 2.1f, 0.9f } };
		float[] color = { 1.0f, 0, 0, 1.0f };
		TessRender.render(GLU.GLU_TESS_WINDING_POSITIVE, star, color);
	}

	public static void main(String[] argv) throws LWJGLException {
		new TessellationTest().run();
	}
}